/*
 * @lc app=leetcode.cn id=168 lang=javascript
 *
 * [168] Excel表列名称
 */

// @lc code=start
/**
 * @param {number} columnNumber
 * @return {string}
 */
var convertToTitle = function(columnNumber) {
    const convertArr = []
    let letterMap = new Map()
    letterMap.set('1','A')
    letterMap.set('2','B')
    letterMap.set('3','C')
    letterMap.set('4','D')
    letterMap.set('5','E')
    letterMap.set('6','F')
    letterMap.set('7','G')
    letterMap.set('8','H')
    letterMap.set('9','I')
    letterMap.set('10','J')
    letterMap.set('11','K')
    letterMap.set('12','L')
    letterMap.set('13','M')
    letterMap.set('14','N')
    letterMap.set('15','O')
    letterMap.set('16','P')
    letterMap.set('17','Q')
    letterMap.set('18','R')
    letterMap.set('19','S')
    letterMap.set('20','T')
    letterMap.set('21','U')
    letterMap.set('22','V')
    letterMap.set('23','W')
    letterMap.set('24','X')
    letterMap.set('25','Y')
    letterMap.set('26','Z')
    for (;columnNumber > 26;) {
        let remainder = (columnNumber - 1) % 26 + 1 // 减一取余再加一，兼容最大的数进位逻辑
        let pushNumber = (columnNumber - remainder) / 26
        convertArr.push(remainder + '')
        columnNumber = pushNumber
    }
    if (columnNumber) {
        convertArr.push(columnNumber + '')
    }
    let res = ''
    for (let index = convertArr.length - 1; index >= 0; index--) {
        const element = letterMap.get(convertArr[index]);
        res += element
    }
    return res
};
// @lc code=end

